package com.apes.auto.car.service;

import com.apes.auto.car.model.GearShiftType;
import com.apes.auto.car.repository.GearShiftTypeRepository;
import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName GearShiftTypeService
 * @Description TODO
 * @Author pengyb
 * @Date 2019/8/28 11:50
 * @Version 1.0
 **/
@Service("gearShiftTypeService")
public class GearShiftTypeService extends DomainService {
    @Autowired
    private GearShiftTypeRepository gearShiftTypeRepository;

    public GearShiftType save(SimpleRequest request) {
        GearShiftType o = request.getO(GearShiftType.class);
        return gearShiftTypeRepository.saveAndFlush(o);
    }

    public String delete(SimpleRequest request) {
        String id = request.get("id");
        Integer versions = request.get("version");
        GearShiftType gearShiftType = request.getO(GearShiftType.class);
        if (gearShiftType == null) throw new RuntimeException("变速箱类型【" + id + "】在系统中不存在。");
        if (gearShiftType.getVersion() != versions) throw new RuntimeException("记录已更新或已删除，请重新提交！");
        gearShiftTypeRepository.delete(gearShiftType);
        return "删除成功";
    }
}
